var express = require('express');
var ejs = require('ejs');
var bodyParser = require('body-parser');
var port = process.env.Port || 3001;
var app = express();

app.set('views', './views/');
app.engine('.html', ejs.__express);
app.set('view engine', 'html');
app.use(bodyParser.urlencoded({ extended: true }));
app.set(express.static(__dirname + '/views')); // 配置模板目录

app.use('/public', express.static(__dirname + '/public')); // 配置静态文件目录
app.use('/favicon.ico', express.static(__dirname + '/public/img/favicon.ico'));

// 路由配置
require('./routes/routes')(app);
app.get('/*', function(req, res) {
    var _path = req.path;
    if (_path === "/") {
        res.render('index');
    } else {
        _path = _path.substring(1, _path.length);
        res.render(_path);
    }
});

app.listen(port, function() {
    console.log('zeroGrid server started on port ' + port);
});
